package com.alibaba.citrus.cr.unified.inventory.functions.allocateRelation;

import com.alibaba.citrus.cr.unified.inventory.repository.AllocateRelationWriteRepository;
import com.alibaba.citrus.cr.common.util.SpringContextUtil;

import com.epoch.app.crunifiedinventory.sdo.AllocateRelationSDO;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

@Data
public class AllocateRelationEntity {
    private AllocateRelationSDO allocateRelationSDO;

    private static AllocateRelationWriteRepository allocateRelationWriteRepository;


    static {
        allocateRelationWriteRepository = SpringContextUtil.getBean(AllocateRelationWriteRepository.class);
    }

    public static AllocateRelationEntity of(AllocateRelationSDO allocateRelationSDO) {
        AllocateRelationEntity allocateRelationEntity = new AllocateRelationEntity();
        allocateRelationEntity.allocateRelationSDO = allocateRelationSDO;
        return allocateRelationEntity;
    }

    public String  create()  {
        String  orderId = "";
        if (StringUtils.isEmpty(allocateRelationSDO.getId())){
            orderId = allocateRelationWriteRepository.save(this.allocateRelationSDO);
        }else{//有主单id
            allocateRelationWriteRepository.modify(this.allocateRelationSDO);
            orderId = allocateRelationSDO.getId();
        }
        return orderId;
    }
}
